package main

import (
	"fmt"
	"time"
)

func main() {
	//testTime()
	//timestamp := time.Now().Unix()
	//testTimestamp(timestamp)

	//testTicker()

	//testConst()

	//testFormat()

	//problem1()
	_start := time.Now().UnixNano()
	problem2()
	_end := time.Now().UnixNano()
	fmt.Printf("problem2 消耗了 微秒:%v\n", (_end-_start)/1000)

}

func testTime() {
	now := time.Now() //实例
	year := now.Year()
	day := now.Day()
	second := now.Second()
	month := now.Month()
	minute := now.Minute()
	fmt.Printf("year=:%v day=%v second=%v month=%v minute=%v \n", year, day, second, month, minute)

	//格式化 不足两位 用 0 补充
	fmt.Printf("year=:%02v day=%02v second=%02v month=%02v minute=%02v \n", year, day, second, month, minute)

	//时间戳
	timestamp := now.Unix()
	fmt.Printf("时间戳:%v\n", timestamp)
}

//时间戳 转 实例
func testTimestamp(timestamp int64) {
	timeInstance := time.Unix(timestamp, 0)
	year := timeInstance.Year()
	day := timeInstance.Day()
	second := timeInstance.Second()
	month := timeInstance.Month()
	minute := timeInstance.Minute()
	fmt.Printf("year=:%02v day=%02v second=%02v month=%02v minute=%02v \n", year, day, second, month, minute)
}

//定时器
func testTicker() {
	ticker := time.Tick(time.Second) //每秒执行
	for i := range ticker {
		fmt.Printf("i=%v\n", i)
		testTask()
	}
}

func testTask() {
	fmt.Printf("do task")
}

func testConst() {
	fmt.Printf("纳秒:%v\n", time.Nanosecond)
	fmt.Printf("微秒:%v\n", time.Microsecond)
	fmt.Printf("毫秒:%v\n", time.Millisecond)
	fmt.Printf("秒:%v\n", time.Second)
}

//格式化输出
func testFormat() {
	now := time.Now()
	fmt.Printf("now:%v\n", now.Format("2006-01-02 15:04:05")) //Golang 创年时间 获取当前时间 必须 填写正确的 Golang 创建时间
}

//获取当前时间
func problem1() {
	var _time string = "2006-01-02 15:04:05"
	fmt.Printf("now:%v\n", time.Now().Format(_time)) //Golang 创年时间 获取当前时间 必须 填写正确的 Golang 创建时间
}

//统计这个func用了多少 纳秒
func problem2() {
	time.Sleep(8 * time.Microsecond)
}
